<template>
  <div class="loginComponent">
    <el-row>
      <el-col :xs="24" :sm="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
      <el-col :xs="24" :sm="8">
        <el-form
          class="loginBox"
          :rules="loginRules"
          label-position="left"
          label-width="80px"
          :model="loginInfo"
          ref="loginRef"
        >
          <el-form-item label="账户名" prop="username">
            <el-input v-model="loginInfo.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="loginInfo.password"></el-input>
          </el-form-item>
          <el-button @click="login" type="primary" style="width:100%">123</el-button>
        </el-form>
      </el-col>
      <el-col :xs="24" :sm="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { loginAdmin } from "../util/http.js";
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      //存储用户名与密码
      loginInfo: {
        username: "admin",
        password: "admin"
      },
      loginRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ]
      }
    };
  },
  computed: {},
  watch: {},
  methods: {
    async login() {
      this.$refs.loginRef.validate(async validate => {
        if (!validate) return this.$message.error("请输入正确的数据");
        const { data: res } = await loginAdmin(
          "/api/user/login.do",
          this.loginInfo
        );
        if (res.status !== 0) return this.$message.error("登录失败");
        this.$router.push("/home");
        this.$message.success("登录成功");
      });
    }
  },
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {}
};
</script> 
<style scoped>
.loginComponent {
  width: 100%;
  height: 100%;
  background: #78c9a9;
  overflow: hidden;
}
.loginBox {
  /* width: 350px; */
  background: #ddd;
  padding: 20px;
  border-radius: 5px;
  /* position: absolute; */
  /* left: 50%;
  top: 50%; */
  /* transform: translate(-50%, -50%); */
  opacity: 0.8;
}
.el-row {
  margin-top: 15%;
  /* transform: translate(0,-50%); */
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
